﻿using CIS.DB;
using CIS.Web.Common;
using CIS.Web.Models;
using CIS.Web.Properties;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Net.Mail;
using System.Threading.Tasks;
using System.Web.Mvc;
using static System.Net.Mime.MediaTypeNames;

namespace CIS.Web.Controllers
{
	[RoutePrefix("ConferenceAttendenceInfo")]
	public class ConferenceAttendenceInfoController : BaseDbController
	{
		private string _importMessage;

		[Route("Index/{ConferenceId}")]
		public async Task<ActionResult> Index(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.ID == conferenceId);

			ViewBag.ConferenceId = conferenceId;
			ViewBag.ConferenceName = conferenceMaster.ConferenceName;
			ViewBag.ControllerName = Resources.ConferenceAttendenceInfo;
			ViewBag.Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn;

			var model = new ConferenceAttendenceInfoModel();
			model.ConferenceId = conferenceId;
			model.CustomizeList = Utility.GetAttendenceCustomizeList(conferenceId);
			LoginUser.ConferenceFunctionIdList = Utility.GetConferenceFunctionIdList(conferenceId);
			return View(model);
		}

		public async Task<JsonCamelCaseResult> GetData(int? page, int? rows, string sort, string order, ConferenceAttendenceInfoModel model)
		{
			int take = rows ?? ConstValues.DefaultGridRows;
			int skip = ((page ?? 1) - 1) * take;

			var sql = from info in DbContext.ConferenceAttendenceInfo.AsNoTracking().Where(x => x.ConferenceId == model.ConferenceId)
				  join titleMaster in DbContext.TitleMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.Title equals titleMaster.ID into t0
				  from title in t0.DefaultIfEmpty()
				  join attendenceIdentityMaster in DbContext.AttendenceIdentityMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.AttendenceIdentityId equals attendenceIdentityMaster.ID into t1
				  from attendenceIdentity in t1.DefaultIfEmpty()
				  join degreeMaster in DbContext.DegreeMaster.AsNoTracking()
					on info.Degree equals degreeMaster.ID into t2
				  from degree in t2.DefaultIfEmpty()
				  join countryMaster in DbContext.LocationMaster.AsNoTracking()
					on info.Country equals countryMaster.ID into t3
				  from country in t3.DefaultIfEmpty()
				  join invoiceMaster in DbContext.ConferenceInvoiceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.InvoiceId equals invoiceMaster.ID into t6
				  from invoice in t6.DefaultIfEmpty()
				  join conferencePaymentMaster in DbContext.ConferencePaymentMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.PaymentTypeId equals conferencePaymentMaster.ID into t7
				  from conferencePayment in t7.DefaultIfEmpty()
				  join sysPaymentMaster in DbContext.SysPaymentMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on conferencePayment.PayId equals sysPaymentMaster.ID into t8
				  from sysPayment in t8.DefaultIfEmpty()
				  join conferenceInfo in DbContext.ConferenceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.ConferenceId equals conferenceInfo.ID into t9
				  from conferenceInfo in t9.DefaultIfEmpty()
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  ConferenceName = conferenceInfo.ConferenceName,
					  FamilyName = info.FamilyName,
					  FirstName = info.FirstName,
					  FullName = info.FullName,
					  Gender = info.Gender,
					  Title = title.TitleName,
					  DegreeName = degree.DegreeName,
					  DegreeNameEn = degree.DegreeNameEn,
					  Job = info.Job,
					  Affiliation = info.Affiliation,
					  Department = info.Department,
					  CardId = info.CardId,
					  AttendenceIdentityId = info.AttendenceIdentityId,
					  IdentityName = attendenceIdentity.IdentityName,
					  Mail = info.Mail,
					  Telephone = info.Telephone,
					  Mobile = info.Mobile,
					  Country = country.Name,
					  CountryEn = country.NameEn,
					  State = info.StateStr,
					  City = info.CityStr,
					  Address = info.Address,
					  ZipCode = info.ZipCode,
					  InvoiceTitle = info.InvoiceTitle,
					  TaxNum = info.TaxNum,
					  AddressAndTel = info.AddressAndTel,
					  Bank = info.Bank,
					  BankAccount = info.BankAccount,
					  InvoiceDetail = invoice.InvoiceDetail,
					  PayTypeId = conferencePayment.ID,
					  PaymentName = sysPayment.PaymentName,
					  PaymentNameEn = sysPayment.PaymentNameEn,
					  HasVisa = info.HasVisa,
					  HasHotel = info.HasHotel,
					  HotelId = info.HotelId,
					  HasMeal = info.HasMeal,
					  HasPage = info.HasPage,
					  TotalFee = info.TotalFee,
					  ActuallyFee = info.ActuallyFee,
					  Discount = info.Discount,
					  Currency = info.Currency,
					  HasContributed = info.HasContributed,
					  HasPaid = info.HasPaid,
					  HasArrived = info.HasArrived,
					  HasPrinted = info.HasPrinted,
					  HasDinner = info.HasDinner,
					  HasInvoiced = info.HasInvoiced,
					  HasSendMail = info.HasSendMail,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  Creator = info.Creator,
					  CreateIP = info.CreateIP,
					  CreateDate = info.CreateDate
				  };

			if (!string.IsNullOrEmpty(model.SelAttendenceIdentity))
			{
				sql = sql.Where(x => x.AttendenceIdentityId == model.SelAttendenceIdentity);
			}

			if (!string.IsNullOrEmpty(model.SelHotel))
			{
				sql = sql.Where(x => x.HotelId == model.SelHotel);
			}

			if (model.SelHasVisa.HasValue)
			{
				sql = sql.Where(x => x.HasVisa == model.SelHasVisa.Value);
			}

			if (model.SelHasPaid.HasValue)
			{
				sql = sql.Where(x => x.HasPaid == model.SelHasPaid.Value);
			}

			if (model.SelHasArrived.HasValue)
			{
				sql = sql.Where(x => x.HasArrived == model.SelHasArrived.Value);
			}

			if (!string.IsNullOrWhiteSpace(model.SelPaidType))
			{
				sql = sql.Where(x => x.PayTypeId == model.SelPaidType);
			}

			if (!string.IsNullOrWhiteSpace(model.SelId))
			{
				var valueId = model.SelId;
				sql = sql.Where(x => x.ID.ToString().Contains(valueId));
			}

			if (!string.IsNullOrWhiteSpace(model.SelSearchId))
			{
				sql = sql.Where(x => x.Mobile.Contains(model.SelSearchId) ||
						x.Telephone.Contains(model.SelSearchId) ||
						x.FullName.Contains(model.SelSearchId) ||
						x.Mail.Contains(model.SelSearchId) ||
						x.Affiliation.Contains(model.SelSearchId));
			}

			int total = await sql.CountAsync();

			if (!string.IsNullOrEmpty(sort))
			{
				sql = sql.OrderBy(sort + ConstValues.chrSpace + order).Skip(skip).Take(take);
			}
			else
			{
				sql = sql.OrderBy(x => x.Sort).ThenByDescending(x => x.CreateDate).Skip(skip).Take(take);
			}

			var sqlResult = await sql.ToListAsync();

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == model.ConferenceId);

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				ConferenceId = x.ConferenceId,
				ConferenceName = x.ConferenceName,
				FullName = x.FullName,
				Gender = x.Gender,
				Title = x.Title,
				DegreeName = conferenceMaster.IsInternational ? x.DegreeNameEn : x.DegreeName,
				Job = x.Job,
				Affiliation = x.Affiliation,
				Department = x.Department,
				IdentityName = x.IdentityName,
				Mail = x.Mail,
				Telephone = x.Telephone,
				Mobile = x.Mobile,
				Country = conferenceMaster.IsInternational ? x.CountryEn : x.Country,
				State = x.State,
				City = x.City,
				Address = x.Address,
				ZipCode = x.ZipCode,
				InvoiceTitle = x.InvoiceTitle,
				TaxNum = x.TaxNum,
				AddressAndTel = x.AddressAndTel,
				Bank = x.Bank,
				BankAccount = x.BankAccount,
				InvoiceDetail = x.InvoiceDetail,
				PaymentName = conferenceMaster.IsInternational ? x.PaymentNameEn : x.PaymentName,
				HasVisa = x.HasVisa,
				HasHotel = x.HasHotel,
				TotalFee = DateTime.Now >= conferenceMaster.BenefitStartDate &&
						DateTime.Now <= conferenceMaster.BenefitEndDate &&
						x.Discount.HasValue ? x.Discount.Value.ToString("N2") : x.TotalFee.Value.ToString("N2"),
				ActuallyFee = x.ActuallyFee.HasValue ? x.ActuallyFee.Value.ToString("N2") : ConstValues.paymentZero.ToString("N2"),
				Currency = x.Currency,
				HasContributed = x.HasContributed,
				HasPaid = x.HasPaid,
				HasArrived = x.HasArrived,
				HasSendMail = x.HasSendMail,
				Creator = x.Creator,
				CreateIP = x.CreateIP,
				CreateDate = conferenceMaster.IsInternational ?
							x.CreateDate.Value.ToString("MM/dd/yyyy") :
							x.CreateDate.Value.ToString("yyyy-MM-dd")
			});

			return JsonCamelCase(new
			{
				Total = total,
				Rows = result,
			},
			JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Modify/{ConferenceId}")]
		public async Task<JsonResult> Modify(ConferenceAttendenceInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ConferenceAttendenceInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result == null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == result.ConferenceId);

				#region ConferenceAttendenceInfo
				if (result.FamilyName != model.FamilyName)
				{
					result.FamilyName = model.FamilyName;
				}
				if (result.FirstName != model.FirstName)
				{
					result.FirstName = model.FirstName;
				}
				if (result.FullName != model.FullName)
				{
					result.FullName = string.IsNullOrEmpty(model.FullName?.Trim()) ? Utility.SetFullName(model.FamilyName?.Trim(), model.FirstName?.Trim(),
								Request.Cookies["_culture"] != null && Request.Cookies["_culture"].Value == ConstValues.Language.En ?
									ConstValues.Language.En : ConstValues.Language.Cn) : model.FullName?.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Gender)))
				{
					result.Gender = model.Gender == ConstValues.Gender.男 ? true : false;
				}
				if (result.Title != model.Title)
				{
					result.Title = model.Title;
				}
				if (result.Degree != model.Degree && model.Degree != 0)
				{
					result.Degree = model.Degree;
				}
				if (result.Job != model.Job)
				{
					result.Job = model.Job;
				}
				if (result.Affiliation != model.Affiliation)
				{
					result.Affiliation = model.Affiliation;
				}
				if (result.Department != model.Department)
				{
					result.Department = model.Department;
				}
				if (result.Country != model.Country)
				{
					result.Country = model.Country;
				}
				if (result.StateStr != model.State)
				{
					result.StateStr = model.State;
				}
				if (result.CityStr != model.City)
				{
					result.CityStr = model.City;
				}
				if (result.Address != model.Address)
				{
					result.Address = model.Address;
				}
				if (result.ZipCode != model.ZipCode)
				{
					result.ZipCode = model.ZipCode;
				}
				if (result.Telephone != model.Telephone)
				{
					result.Telephone = model.Telephone;
				}
				if (result.Mobile != model.Mobile)
				{
					result.Mobile = model.Mobile;
				}
				if (result.CardId != model.CardId)
				{
					result.CardId = model.CardId;
				}
				if (result.AttendenceIdentityId != model.AttendenceIdentityId)
				{
					result.AttendenceIdentityId = model.AttendenceIdentityId;
				}
				if (!string.IsNullOrWhiteSpace(model.InvoiceTitle))
				{
					if (result.InvoiceTitle != model.InvoiceTitle)
					{
						result.InvoiceTitle = model.InvoiceTitle;
					}
					if (result.TaxNum != model.TaxNum)
					{
						result.TaxNum = model.TaxNum;
					}
					if (result.AddressAndTel != model.AddressAndTel)
					{
						result.AddressAndTel = model.AddressAndTel;
					}
					if (result.Bank != model.Bank)
					{
						result.Bank = model.Bank;
					}
					if (result.BankAccount != model.BankAccount)
					{
						result.BankAccount = model.BankAccount;
					}
				}
				if (result.InvoiceId != model.InvoiceId)
				{
					result.InvoiceId = model.InvoiceId;
				}
				if (model.FavouriteTopic != null && model.FavouriteTopic.Length > 0)
				{
					result.FavouriteTopicId = string.Join(ConstValues.strSemicolon, model.FavouriteTopic);
				}
				else
				{
					result.FavouriteTopicId = string.Empty;
				}
				if (!(string.IsNullOrEmpty(model.Customize1)) && result.Customize1 != model.Customize1)
				{
					result.Customize1 = model.Customize1.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize2)) && result.Customize2 != model.Customize2)
				{
					result.Customize2 = model.Customize2.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize3)) && result.Customize3 != model.Customize3)
				{
					result.Customize3 = model.Customize3.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize4)) && result.Customize4 != model.Customize4)
				{
					result.Customize4 = model.Customize4.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize5)) && result.Customize5 != model.Customize5)
				{
					result.Customize5 = model.Customize5.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize6)) && result.Customize6 != model.Customize6)
				{
					result.Customize6 = model.Customize6.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize7)) && result.Customize7 != model.Customize7)
				{
					result.Customize7 = model.Customize7.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize8)) && result.Customize8 != model.Customize8)
				{
					result.Customize8 = model.Customize8.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize9)) && result.Customize9 != model.Customize9)
				{
					result.Customize9 = model.Customize9.Trim();
				}
				if (!(string.IsNullOrEmpty(model.Customize10)) && result.Customize10 != model.Customize10)
				{
					result.Customize10 = model.Customize10.Trim();
				}
				if (!string.IsNullOrEmpty(model.PaymentTypeId) && result.PaymentTypeId != model.PaymentTypeId)
				{
					result.PaymentTypeId = model.PaymentTypeId;
				}
				if (!string.IsNullOrEmpty(model.Currency) && result.Currency != model.Currency)
				{
					result.Currency = model.Currency;
				}
				#endregion

				#region ProfilePaymentInfo
				var pageFee = DbContext.ProfilePaymentInfo
						.FirstOrDefault(x => x.AttendenceId == model.Id &&
							x.FeeType == ConstValues.FeeType.版面费);

				if (pageFee == null)
				{
					if (!string.IsNullOrEmpty(model.PageFeeId))
					{
						var feeMaster = DbContext.FeePageMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.PageFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.版面费,
								FeeId = model.PageFeeId,
								Count = 1,
								Fee = feeMaster.Price.Value,
								Discount = feeMaster.Price.Value,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += feeMaster.Price.Value;
							result.Discount += feeMaster.Price.Value;
							result.Currency = feeMaster.Currency;
							result.HasPage = true;
						}
					}
				}
				else
				{
					if (pageFee.FeeId != model.PageFeeId)
					{
						result.TotalFee = result.TotalFee - pageFee.Fee;
						result.Discount = result.Discount - pageFee.Discount;
						DbContext.ProfilePaymentInfo.Remove(pageFee);

						var feeMaster = DbContext.FeePageMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.PageFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.版面费,
								FeeId = model.PageFeeId,
								Count = 1,
								Fee = feeMaster.Price.Value,
								Discount = feeMaster.Price.Value,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += feeMaster.Price.Value;
							result.Discount += feeMaster.Price.Value;
							result.Currency = feeMaster.Currency;
							result.HasPage = true;
						}
					}
					else
					{
						result.HasPage = false;
					}
				}

				var attendenceFee = DbContext.ProfilePaymentInfo
						.FirstOrDefault(x => x.AttendenceId == model.Id &&
							x.FeeType == ConstValues.FeeType.参会费);

				if (attendenceFee == null)
				{
					if (!string.IsNullOrEmpty(model.AttendenceFeeId))
					{
						var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.AttendenceFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							double originFee = feeMaster.Price.Value;
							double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.参会费,
								FeeId = model.AttendenceFeeId,
								Count = 1,
								Fee = originFee,
								Discount = discountFee,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += originFee;
							result.Discount += discountFee;
							result.Currency = feeMaster.Currency;
						}
					}
				}
				else
				{
					if (attendenceFee.FeeId != model.AttendenceFeeId)
					{
						result.TotalFee = result.TotalFee - attendenceFee.Fee;
						result.Discount = result.Discount - attendenceFee.Discount;
						DbContext.ProfilePaymentInfo.Remove(attendenceFee);

						var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.AttendenceFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							double originFee = feeMaster.Price.Value;
							double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.参会费,
								FeeId = model.AttendenceFeeId,
								Count = 1,
								Fee = originFee,
								Discount = discountFee,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += originFee;
							result.Discount += discountFee;
							result.Currency = feeMaster.Currency;
						}
					}
				}

				var mealFee = DbContext.ProfilePaymentInfo
						.FirstOrDefault(x => x.AttendenceId == model.Id &&
							x.FeeType == ConstValues.FeeType.餐费);

				if (mealFee == null)
				{
					if (!string.IsNullOrEmpty(model.MealFeeId))
					{
						var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.MealFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.餐费,
								FeeId = model.MealFeeId,
								Count = 1,
								Fee = feeMaster.Price.Value,
								Discount = feeMaster.Price.Value,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += feeMaster.Price.Value;
							result.Discount += feeMaster.Price.Value;
							result.Currency = feeMaster.Currency;
							result.HasMeal = true;
						}
					}
				}
				else
				{
					if (mealFee.FeeId != model.MealFeeId)
					{
						result.TotalFee = result.TotalFee - mealFee.Fee;
						result.Discount = result.Discount - mealFee.Discount;
						DbContext.ProfilePaymentInfo.Remove(mealFee);

						var feeMaster = DbContext.FeeMealMaster.AsNoTracking()
								.FirstOrDefault(x => x.ID == model.MealFeeId);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.餐费,
								FeeId = model.MealFeeId,
								Count = 1,
								Fee = feeMaster.Price.Value,
								Discount = feeMaster.Price.Value,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += feeMaster.Price.Value;
							result.Discount += feeMaster.Price.Value;
							result.Currency = feeMaster.Currency;
							result.HasMeal = true;
						}
					}
					else
					{
						result.HasMeal = false;
					}
				}

				var eventFee = await DbContext.ProfilePaymentInfo
						.Where(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.同期活动费)
						.ToListAsync();
				if (eventFee.Count > 0)
				{
					for (var i = 0; i < eventFee.Count; i++)
					{
						result.TotalFee -= eventFee[i].Fee;
						result.Discount -= eventFee[i].Fee;
					}

					DbContext.ProfilePaymentInfo.RemoveRange(eventFee);

				}
				if (!string.IsNullOrEmpty(model.HidEventIdList) && !string.IsNullOrEmpty(model.HidCountList))
				{
					var concurrentEventList = model.HidEventIdList.Split(ConstValues.chrComma);
					var concurrentEventCount = model.HidCountList.Split(ConstValues.chrComma);
					for (var index = 0; index < concurrentEventList.Length; index++)
					{
						string tmp = concurrentEventList[index];
						int count = int.Parse(concurrentEventCount[index]);

						var feeMaster = DbContext.FeeConcurrentEventMaster.AsNoTracking().FirstOrDefault(x => x.ConcurrentEventId == tmp && x.Status == ConstValues.Status.正常
									&& (x.AttendenceIdentityId == model.AttendenceIdentityId || x.AttendenceIdentityId == ConstValues.ApplicableForAll)
									&& x.Currency == model.Currency);

						if (feeMaster != null && count != 0)
						{
							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = result.Creator,
								AttendenceId = model.Id,
								FeeType = ConstValues.FeeType.同期活动费,
								FeeId = feeMaster.ID,
								Count = count,
								Fee = feeMaster.Price.Value * count,
								Discount = feeMaster.Price.Value * count,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							result.TotalFee += feeMaster.Price.Value * count;
							result.Discount += feeMaster.Price.Value * count;
							result.Currency = feeMaster.Currency;
						}
					}
				}
				#endregion

				result.Sort = model.Sort.HasValue ? model.Sort.Value : ConstValues.DefaultSort;
				result.Remark = model.Remark?.Trim();
				result.Updater = LoginUser.UserName;
				result.UpdateIP = LoginUser.IP;
				result.UpdateDate = DateTime.Now;

				Utility.SaveInvoiceInfo(LoginUser, new InvoiceModel
				{
					InvoiceTitle = model.InvoiceTitle,
					TaxNum = model.TaxNum,
					AddressAndTel = model.AddressAndTel,
					Bank = model.Bank,
					BankAccount = model.BankAccount,
				});

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Delete/{ConferenceId}")]
		public async Task<JsonResult> Delete(ConferenceFormModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ConferenceAttendenceInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result != null)
			{
				if (result.HasPaid)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgUsingCanNotDelete),
							JsonRequestBehavior.AllowGet);
				}

				using (var transaction = DbContext.Database.BeginTransaction())
				{
					DbContext.ConferenceAttendenceInfo.Remove(result);

					var profilePaymentInfoList = await DbContext.ProfilePaymentInfo
							.Where(x => x.AttendenceId == model.Id).ToListAsync();
					DbContext.ProfilePaymentInfo.RemoveRange(profilePaymentInfoList);

					var profilePaymentRecordList = await DbContext.ProfilePaymentRecord
							.Where(x => x.AttendenceId == model.Id).ToListAsync();
					DbContext.ProfilePaymentRecord.RemoveRange(profilePaymentRecordList);

					var conferencePayStatusInfoList = await DbContext.ConferencePayStatusInfo
							.Where(x => x.AttendenceId == model.Id).ToListAsync();
					DbContext.ConferencePayStatusInfo.RemoveRange(conferencePayStatusInfoList);

					await DbContext.SaveChangesAsync();
					transaction.Commit();
				}

				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}

		public async Task<JsonCamelCaseResult> GetOtherFeeData(string id)
		{
			var sql = DbContext.ProfilePaymentInfo.AsNoTracking()
					.Where(x => x.AttendenceId == id &&
						x.FeeType == ConstValues.FeeType.其他费用)
					.OrderBy(x => x.CreateDate)
					.Join(DbContext.FeeOtherMaster.AsNoTracking()
						.Where(x => x.Status == ConstValues.Status.正常),
					pay => pay.FeeId,
					fee => fee.ID,
					(pay, fee) => new
					{
						Id = pay.ID,
						FeeName = fee.FeeName,
						Count = pay.Count,
						UnitPrice = fee.Price,
						Currency = fee.Currency,
						Price = pay.Fee
					});

			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				Id = x.Id,
				FeeName = x.FeeName,
				Count = x.Count,
				UnitPrice = x.UnitPrice.Value.ToString("N2"),
				Currency = x.Currency,
				Price = x.Price.ToString("N2")
			});

			return JsonCamelCase(result, JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("CreateOtherFee/{ConferenceId}")]
		public async Task<JsonResult> CreateOtherFee(OtherFeeModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ProfilePaymentInfo
					.FirstOrDefaultAsync(x => x.AttendenceId == model.AttendenceId &&
						x.FeeType == ConstValues.FeeType.其他费用 &&
						x.FeeId == model.OtherFeeId);

			if (result != null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(
						string.Format(Resources.MsgRecordExist, Resources.FeeName)),
						JsonRequestBehavior.AllowGet);
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var otherFee = await DbContext.FeeOtherMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == model.OtherFeeId);

				if (otherFee != null && otherFee.Price.HasValue)
				{
					var info = await DbContext.ConferenceAttendenceInfo
							.FirstOrDefaultAsync(x => x.ID == model.AttendenceId);

					info.TotalFee = info.TotalFee + otherFee.Price.Value * model.Count.Value;
					info.Discount = info.Discount + otherFee.Price.Value * model.Count.Value;
					info.Currency = otherFee.Currency;
					info.Updater = LoginUser.UserName;
					info.UpdateIP = LoginUser.IP;
					info.UpdateDate = DateTime.Now;

					var profilePaymentInfo = new ProfilePaymentInfo
					{
						ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
						UserName = info.Creator,
						AttendenceId = model.AttendenceId,
						FeeType = ConstValues.FeeType.其他费用,
						FeeId = model.OtherFeeId,
						Count = model.Count,
						Fee = otherFee.Price.Value * model.Count.Value,
						Discount = otherFee.Price.Value * model.Count.Value,
						Currency = otherFee.Currency,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now
					};

					DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);
				}

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSubmit),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("DeleteOtherFee/{ConferenceId}")]
		public async Task<JsonResult> DeleteOtherFee(OtherFeeModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			var result = await DbContext.ProfilePaymentInfo
					.FirstOrDefaultAsync(x => x.ID == model.Id);

			if (result == null)
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}

			using (var transaction = DbContext.Database.BeginTransaction())
			{
				var info = await DbContext.ConferenceAttendenceInfo
						.FirstOrDefaultAsync(x => x.ID == model.AttendenceId);

				info.TotalFee = info.TotalFee - result.Fee;
				info.Discount = info.Discount - result.Fee;
				info.Updater = LoginUser.UserName;
				info.UpdateIP = LoginUser.IP;
				info.UpdateDate = DateTime.Now;

				DbContext.ProfilePaymentInfo.Remove(result);

				await DbContext.SaveChangesAsync();
				transaction.Commit();
			}

			return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessDelete),
					JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<FileResult> Export(string allId, SelectOptionModel selModel)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", selModel.ConferenceId);

			var ids = allId.Split(ConstValues.chrComma);
			var sql = from info in DbContext.ConferenceAttendenceInfo.AsNoTracking().Where(x => ids.Contains(x.ID.ToString()))
				  join attendenceIdentityMaster in DbContext.AttendenceIdentityMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.AttendenceIdentityId equals attendenceIdentityMaster.ID into t1
				  from attendenceIdentity in t1.DefaultIfEmpty()
				  join degreeMaster in DbContext.DegreeMaster.AsNoTracking()
					on info.Degree equals degreeMaster.ID into t2
				  from degree in t2.DefaultIfEmpty()
				  join locationMaster in DbContext.LocationMaster.AsNoTracking()
					on info.Country equals locationMaster.ID into t3
				  from location in t3.DefaultIfEmpty()
				  join invoiceMaster in DbContext.ConferenceInvoiceMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.InvoiceId equals invoiceMaster.ID into t4
				  from invoice in t4.DefaultIfEmpty()
				  join conferencePaymentMaster in DbContext.ConferencePaymentMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.PaymentTypeId equals conferencePaymentMaster.ID into t5
				  from conferencePayment in t5.DefaultIfEmpty()
				  join sysPaymentMaster in DbContext.SysPaymentMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on conferencePayment.PayId equals sysPaymentMaster.ID into t6
				  from sysPayment in t6.DefaultIfEmpty()
				  join hotelMaster in DbContext.HotelMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.HotelId equals hotelMaster.ID into t7
				  from hotel in t7.DefaultIfEmpty()
				  join titleMaster in DbContext.TitleMaster.AsNoTracking().Where(x => x.Status == ConstValues.Status.正常)
					on info.Title equals titleMaster.ID into t8
				  from title in t8.DefaultIfEmpty()
				  select new
				  {
					  Id = info.ID,
					  ConferenceId = info.ConferenceId,
					  FullName = info.FullName,
					  Gender = info.Gender,
					  Title = info.Title,
					  TitleName = title.TitleName,
					  DegreeId = info.Degree,
					  DegreeName = degree.DegreeName,
					  Job = info.Job,
					  Affiliation = info.Affiliation,
					  Department = info.Department,
					  CardId = info.CardId,
					  AttendenceIdentityId = info.AttendenceIdentityId,
					  IdentityName = attendenceIdentity.IdentityName,
					  EssayId = info.EssayId,
					  Mail = info.Mail,
					  Telephone = info.Telephone,
					  Mobile = info.Mobile,
					  CountryId = info.Country,
					  Country = location.Name,
					  Address = info.Address,
					  ZipCode = info.ZipCode,
					  InvoiceTitle = info.InvoiceTitle,
					  TaxNum = info.TaxNum,
					  AddressAndTel = info.AddressAndTel,
					  Bank = info.Bank,
					  BankAccount = info.BankAccount,
					  InvoiceId = info.InvoiceId,
					  InvoiceDetail = invoice.InvoiceDetail,
					  PaymentTypeId = info.PaymentTypeId,
					  PaymentName = sysPayment.PaymentName,
					  HasVisa = info.HasVisa,
					  HotelId = info.HotelId,
					  HotelName = hotel.HotelName,
					  CheckinDate = info.CheckinDate,
					  CheckoutDate = info.CheckoutDate,
					  CheckinDaysCount = info.CheckinDaysCount,
					  HotelRemark = info.HotelRemark,
					  ArrivalDate = info.ArrivalDate,
					  ArrivalFlight = info.ArrivalFlight,
					  DeparturalDate = info.DeparturalDate,
					  DeparturalFlight = info.DeparturalFlight,
					  TotalFee = info.TotalFee,
					  ActuallyFee = info.ActuallyFee,
					  Discount = info.Discount,
					  Currency = info.Currency,
					  HasPaid = info.HasPaid,
					  HasArrived = info.HasArrived,
					  InvoiceNum = info.InvoiceNum,
					  HasSendMail = info.HasSendMail,
					  Creator = info.Creator,
					  CreateIP = info.CreateIP,
					  CreateDate = info.CreateDate,
					  HasDinner = info.HasDinner,
					  HasPrinted = info.HasPrinted,
					  Remark = info.Remark,
					  HasInvoiced = info.HasInvoiced,
					  FavouriteTopicId = info.FavouriteTopicId,
					  Customize1 = info.Customize1,
					  Customize2 = info.Customize2,
					  Customize3 = info.Customize3,
					  Customize4 = info.Customize4,
					  Customize5 = info.Customize5,
					  Customize6 = info.Customize6,
					  Customize7 = info.Customize7,
					  Customize8 = info.Customize8,
					  Customize9 = info.Customize9,
					  Customize10 = info.Customize10,
				  };

			var result = await sql.ToListAsync();

			var conferenceId = result.FirstOrDefault().ConferenceId;

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId);

			var export = conferenceMaster.IsInternational ? Resources.export_attendenceInfoEN : Resources.export_attendenceInfoCN;

			XSSFWorkbook workbook;

			using (MemoryStream readStream = new MemoryStream(export))
			{
				workbook = new XSSFWorkbook(readStream);
				ISheet sheet = workbook.GetSheetAt(0);

				var count = 0;
				IRow headLine = sheet.CreateRow(count);
				int headColumn = 0;
				ICell headCell = headLine.CreateCell(headColumn);
				if (selModel.AttendenceId == "on")
				{

					headCell.SetCellValue(Resources.AttendenceId);
					headColumn++;
				}
				if (selModel.AttendIdentity == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.AttendenceIdentity);
					headColumn++;
				}
				if (selModel.FullName == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.FullName);
					headColumn++;
				}
				if (selModel.Gender == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Gender);
					headColumn++;
				}
				if (selModel.Call == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.JobTitle);
					headColumn++;
				}
				if (selModel.Degree == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.HighestEducation);
					headColumn++;
				}
				if (selModel.Career == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Job);
					headColumn++;
				}
				if (selModel.Affiliation == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Affiliation);
					headColumn++;
				}
				if (selModel.Department == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Department);
					headColumn++;
				}
				if (selModel.Country == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Country);
					headColumn++;
				}
				if (selModel.Address == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Address);
					headColumn++;
				}
				if (selModel.ZipCode == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.ZipCode);
					headColumn++;
				}
				if (selModel.Telephone == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Telephone);
					headColumn++;
				}
				if (selModel.Mobile == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Mobile);
					headColumn++;
				}
				if (selModel.Mail == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Mail);
					headColumn++;
				}
				if (selModel.CardId == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.CardId);
					headColumn++;
				}
				if (selModel.HasArrived == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.ArriveStatus);
					headColumn++;
				}
				if (selModel.PayType == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.PaidStatus);
					headColumn++;
				}
				if (selModel.PaidType == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.PaidType);
					headColumn++;
				}
				if (selModel.Currency == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Currency);
					headColumn++;
				}
				if (selModel.NeedPay == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.PaymentShouldPay);
					headColumn++;
				}
				if (selModel.ActuallyPay == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.PaymentHasPay);
					headColumn++;
				}
				if (selModel.FeeAttend == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.FeeAttend);
					headColumn++;
				}
				if (selModel.FeePage == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.FeePage);
					headColumn++;
				}
				if (selModel.MealFee == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.MealFee);
					headColumn++;
				}
				if (selModel.OtherFee == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.OtherFee);
					headColumn++;
				}
				if (selModel.ConcurrentEvent == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.ConcurrentEvent);
					headColumn++;
				}
				if (selModel.DinnerStatus == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.DinnerStatus);
					headColumn++;
				}
				if (selModel.AttendCard == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.AttendCard);
					headColumn++;
				}
				if (selModel.Remark == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Remark);
					headColumn++;
				}
				if (selModel.IsInvoice == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.IsInvoice);
					headColumn++;
				}

				if (selModel.TaxTitle == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.InvoiceTitle);
					headColumn++;
				}
				if (selModel.TaxNum == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.TaxNum);
					headColumn++;
				}
				if (selModel.AddressAndTel == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.AddressAndTel);
					headColumn++;
				}
				if (selModel.Bank == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Bank);
					headColumn++;
				}
				if (selModel.BankAccount == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.BankAccount);
					headColumn++;
				}
				if (selModel.InvoiceDetail == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.InvoiceId);
					headColumn++;
				}
				if (selModel.InvoiceNum == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.InvoiceNum);
					headColumn++;
				}
				if (selModel.VisaInfo == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Visa);
					headColumn++;
				}
				if (selModel.HasContributed == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.EssayId);
					headColumn++;
				}
				if (selModel.FavouriteTopic == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.FavouriteTopic);
					headColumn++;
				}
				if (selModel.SendQuizStatus == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.SendQuizStatus);
					headColumn++;
				}
				if (selModel.Creator == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.Creator);
					headColumn++;
				}
				if (selModel.CreateIP == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.CreateIP);
					headColumn++;
				}
				if (selModel.CreateDate == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(Resources.CreateDate);
					headColumn++;
				}
				if (selModel.Customize1 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize1")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize2 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize2")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize3 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize3")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize4 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize4")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize5 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize5")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize6 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize6")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize7 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize7")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize8 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize8")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize9 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize9")?.DisplayName);
					headColumn++;
				}
				if (selModel.Customize10 == "on")
				{
					headCell = headLine.CreateCell(headColumn);
					headCell.SetCellValue(DbContext.ConferenceAttendenceForm.AsNoTracking()
							.FirstOrDefault(x => x.ConferenceId == selModel.ConferenceId && x.Key == "Customize10")?.DisplayName);
					headColumn++;
				}

				foreach (var model in result)
				{
					count += 1;
					IRow row = sheet.CreateRow(count);

					// 注册号
					int column = 0;
					ICell cell = row.CreateCell(column);
					if (selModel.AttendenceId == "on")
					{
						cell.SetCellValue(model.Id);
						column++;
					}
					// 参会身份
					if (selModel.AttendIdentity == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(!string.IsNullOrEmpty(model.IdentityName) ? model.IdentityName.ToString() : string.Empty);
						column++;
					}
					// 姓名
					if (selModel.FullName == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.FullName);
						column++;
					}
					// 性别
					if (selModel.Gender == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Gender ? Resources.Male : Resources.Female);
						column++;
					}
					// 职称
					if (selModel.Call == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(!string.IsNullOrEmpty(model.TitleName) ? model.TitleName.ToString() : string.Empty);
						column++;
					}
					// 最高学历
					if (selModel.Degree == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.DegreeId.HasValue && model.DegreeId != 0 ? model.DegreeName.ToString() : string.Empty);
						column++;
					}
					// 职务
					if (selModel.Career == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Job);
						column++;
					}
					// 单位
					if (selModel.Affiliation == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Affiliation);
						column++;
					}
					// 部门
					if (selModel.Department == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Department);
						column++;
					}
					// 国家
					if (selModel.Country == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.CountryId.HasValue ? model.Country.ToString() : string.Empty);
						column++;
					}
					// 地址
					if (selModel.Address == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Address);
						column++;
					}

					// 邮编
					if (selModel.ZipCode == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.ZipCode);
						column++;
					}
					// 电话
					if (selModel.Telephone == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Telephone);
						column++;
					}
					// 手机
					if (selModel.Mobile == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Mobile);
						column++;
					}
					// 邮箱
					if (selModel.Mail == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Mail);
						column++;
					}
					// 身份证
					if (selModel.CardId == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.CardId);
						column++;
					}
					// 是否报到
					if (selModel.HasArrived == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasArrived ? Resources.IsArrived : Resources.IsNotArrived);
						column++;
					}
					// 是否缴费
					if (selModel.PayType == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasPaid ? Resources.HasPaid : Resources.HasNotPaid);
						column++;
					}
					// 缴费方式
					if (selModel.PaidType == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(!string.IsNullOrEmpty(model.PaymentName) ? model.PaymentName.ToString() : string.Empty);
						column++;
					}
					// 币种
					if (selModel.Currency == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Currency);
						column++;
					}
					// 总费用 -- 应缴费用
					if (selModel.NeedPay == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(DateTime.Now >= conferenceMaster.BenefitStartDate &&
									DateTime.Now <= conferenceMaster.BenefitEndDate &&
									model.Discount.HasValue ?
									model.Discount.Value.ToString("N2") :
									model.TotalFee.Value.ToString("N2"));
						column++;
					}
					//实缴费用
					if (selModel.ActuallyPay == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.ActuallyFee.HasValue ?
									model.ActuallyFee.Value.ToString("N2") :
									ConstValues.paymentZero.ToString("N2"));
						column++;

					}
					//参会费
					if (selModel.FeeAttend == "on")
					{
						var feeName = string.Empty;
						var FeeId = DbContext.ProfilePaymentInfo.AsNoTracking().FirstOrDefault(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.参会费)?.FeeId;
						if (!string.IsNullOrEmpty(FeeId))
						{
							var feeAttendenceMaster = DbContext.FeeAttendenceMaster.AsNoTracking().FirstOrDefault(x => x.ID == FeeId);
							feeName += feeAttendenceMaster.RegisterType;
							feeName += ConstValues.chrSpace;
							feeName += feeAttendenceMaster.Currency;
							feeName += conferenceMaster.BenefitStartDate <= DateTime.Now && DateTime.Now <= conferenceMaster.BenefitEndDate ?
										feeAttendenceMaster.Price.Value :
										feeAttendenceMaster.Discount.Value;
						}

						cell = row.CreateCell(column);
						cell.SetCellValue(feeName);
						column++;
					}
					//版面费
					if (selModel.FeePage == "on")
					{
						var feeName = "";
						var FeeId = DbContext.ProfilePaymentInfo.AsNoTracking().FirstOrDefault(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.版面费)?.FeeId;
						if (!string.IsNullOrEmpty(FeeId))
						{
							var feePageMaster = DbContext.FeePageMaster.AsNoTracking().FirstOrDefault(x => x.ID == FeeId);
							feeName = feePageMaster.FeeName;
							feeName += ConstValues.chrSpace;
							feeName += feePageMaster.Currency;
							feeName += feePageMaster.Price;
						}

						cell = row.CreateCell(column);
						cell.SetCellValue(feeName);
						column++;
					}
					//餐费
					if (selModel.MealFee == "on")
					{
						var feeName = "";
						var FeeId = DbContext.ProfilePaymentInfo.AsNoTracking().FirstOrDefault(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.餐费)?.FeeId;
						if (!string.IsNullOrEmpty(FeeId))
						{
							var feeMealMaster = DbContext.FeeMealMaster.AsNoTracking().FirstOrDefault(x => x.ID == FeeId);
							feeName = feeMealMaster.FeeName;
							feeName += ConstValues.chrSpace;
							feeName += feeMealMaster.Currency;
							feeName += feeMealMaster.Price;
						}

						cell = row.CreateCell(column);
						cell.SetCellValue(feeName);
						column++;
					}
					//其他费用
					if (selModel.OtherFee == "on")
					{
						var otherFee = string.Empty;
						var profilePaymentInfo = DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.其他费用).OrderBy(x => x.CreateDate).ToList();
						if (profilePaymentInfo.Count > 0)
						{
							for (var index = 0; index < profilePaymentInfo.Count; index++)
							{
								var feeID = profilePaymentInfo[index].FeeId;
								var otherFeeMaster = DbContext.FeeOtherMaster.FirstOrDefault(x => x.ID == feeID);
								if (otherFeeMaster != null)
								{
									if (index == 0)
									{
										otherFee += otherFeeMaster.FeeName;
										otherFee += ConstValues.chrSpace;
										otherFee += otherFeeMaster.Currency;
										otherFee += otherFeeMaster.Price;
									}
									else
									{
										otherFee += ConstValues.strSemicolon + otherFeeMaster.FeeName;
										otherFee += ConstValues.chrSpace;
										otherFee += otherFeeMaster.Currency;
										otherFee += otherFeeMaster.Price;
									}
								}
							}
						}
						cell = row.CreateCell(column);
						cell.SetCellValue(otherFee);
						column++;
					}
					//同期活动
					if (selModel.ConcurrentEvent == "on")
					{
						var concurrentEvent = string.Empty;
						var eventInfo = DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.AttendenceId == model.Id && x.FeeType == ConstValues.FeeType.同期活动费).OrderBy(x => x.CreateDate).ToList();
						if (eventInfo.Count > 0)
						{
							for (var index = 0; index < eventInfo.Count; index++)
							{
								var feeID = eventInfo[index].FeeId;
								var feeConcurrentEventMaster = DbContext.FeeConcurrentEventMaster.FirstOrDefault(x => x.ID == feeID);
								if (feeConcurrentEventMaster != null)
								{
									var eventName = DbContext.ConcurrentEventMaster.FirstOrDefault(x => x.ID == feeConcurrentEventMaster.ConcurrentEventId).EventName;
									if (index == 0)
									{
										concurrentEvent += eventName;
										concurrentEvent += ConstValues.chrSpace;
										concurrentEvent += feeConcurrentEventMaster.Currency;
										concurrentEvent += feeConcurrentEventMaster.Price;
									}
									else
									{
										concurrentEvent += ConstValues.strSemicolon + eventName;
										concurrentEvent += ConstValues.chrSpace;
										concurrentEvent += feeConcurrentEventMaster.Currency;
										concurrentEvent += feeConcurrentEventMaster.Price;
									}
								}
							}
						}
						cell = row.CreateCell(column);
						cell.SetCellValue(concurrentEvent);
						column++;
					}
					// 晚宴（是/否）
					if (selModel.DinnerStatus == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasDinner ? Resources.Yes : Resources.No);
						column++;
					}
					// 胸牌（已打印/未打印）
					if (selModel.AttendCard == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasPrinted ? Resources.CardHasPrint : Resources.CardHasNotPrint);
						column++;
					}
					// 备注（现场管理处的备注）
					if (selModel.Remark == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Remark);
						column++;
					}
					// 发票状态（已开票/未开票）
					if (selModel.IsInvoice == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasInvoiced ? Resources.HasInvoiced : Resources.HasNotInvoiced);
						column++;
					}
					// 发票抬头
					if (selModel.TaxTitle == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.InvoiceTitle);
						column++;
					}
					// 税号
					if (selModel.TaxNum == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.TaxNum);
						column++;
					}
					// 地址及电话
					if (selModel.AddressAndTel == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.AddressAndTel);
						column++;
					}
					// 开户行
					if (selModel.Bank == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Bank);
						column++;
					}
					// 银行账号
					if (selModel.BankAccount == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.BankAccount);
						column++;
					}
					// 发票明细
					if (selModel.InvoiceDetail == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(!string.IsNullOrEmpty(model.InvoiceDetail) ? model.InvoiceDetail.ToString() : string.Empty);
						column++;
					}
					// 发票编号（现场管理处的发票编号）
					if (selModel.InvoiceNum == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.InvoiceNum);
						column++;
					}
					// 签证
					if (selModel.VisaInfo == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasVisa ? Resources.Yes : Resources.No);
						column++;
					}
					// 论文编号
					if (selModel.HasContributed == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.EssayId);
						column++;
					}
					// 感兴趣的专题（列出并;隔开）
					if (selModel.FavouriteTopic == "on")
					{
						var topicName = string.Empty;
						if (!string.IsNullOrEmpty(model.FavouriteTopicId))
						{
							var topicIdList = model.FavouriteTopicId.Split(ConstValues.chrSemicolon);
							if (topicIdList.Length > 0)
							{
								foreach (var topicId in topicIdList)
								{
									if (!string.IsNullOrWhiteSpace(topicId))
									{
										var topicMaster = DbContext.TopicMaster.FirstOrDefault(x => x.ID == topicId);
										if (string.IsNullOrEmpty(topicName))
										{
											topicName += topicMaster.TopicName;
										}
										else
										{
											topicName += ConstValues.strSemicolon + topicMaster.TopicName;
										}
									}
								}
							}
						}
						cell = row.CreateCell(column);
						cell.SetCellValue(topicName);
						column++;
					}
					//是否发送问卷
					if (selModel.SendQuizStatus == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.HasSendMail ? Resources.HasSend : Resources.HasNotSend);
						column++;
					}
					// 创建者
					if (selModel.Creator == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Creator);
						column++;
					}
					// 创建IP
					if (selModel.CreateIP == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.CreateIP);
						column++;
					}
					// 创建日期
					if (selModel.CreateDate == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(conferenceMaster.IsInternational ?
									model.CreateDate.Value.ToString("MM/dd/yyyy") :
									model.CreateDate.Value.ToString("yyyy-MM-dd"));
						column++;
					}
					// 自定义1
					if (selModel.Customize1 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize1);
						column++;
					}
					// 自定义2
					if (selModel.Customize2 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize2);
						column++;
					}
					// 自定义3
					if (selModel.Customize3 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize3);
						column++;
					}
					// 自定义4
					if (selModel.Customize4 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize4);
						column++;
					}
					// 自定义5
					if (selModel.Customize5 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize5);
						column++;
					}
					// 自定义6
					if (selModel.Customize6 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize6);
						column++;
					}
					// 自定义7
					if (selModel.Customize7 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize7);
						column++;
					}
					// 自定义8
					if (selModel.Customize8 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize8);
						column++;
					}
					// 自定义9
					if (selModel.Customize9 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize9);
						column++;
					}
					// 自定义10
					if (selModel.Customize10 == "on")
					{
						cell = row.CreateCell(column);
						cell.SetCellValue(model.Customize10);
						column++;
					}
				}
			}

			MemoryStream exportStream = new MemoryStream();
			workbook.Write(exportStream);
			exportStream.Flush();
			exportStream.Position = 0;

			return File(exportStream, Application.Octet,
					$"export_attendenceInfo_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		public async Task<JsonResult> SendMail(string conferenceId, string allId, string quizId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);
			var ids = allId.Split(ConstValues.chrAnd);

			var result = await DbContext.ConferenceAttendenceInfo.AsNoTracking()
					.Where(x => ids.Contains(x.ID.ToString()))
					.ToListAsync();

			var conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
						x.MailType == ConstValues.MailType.会议邮箱 &&
						x.ConferenceId == conferenceId);

			if (conferenceMailServerMaster == null)
			{
				conferenceMailServerMaster = await DbContext.ConferenceMailServerMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
							x.MailType == ConstValues.MailType.会议邮箱 &&
							x.ConferenceId == conferenceId);
			}

			var strMsg = string.Empty;
			if (conferenceMailServerMaster != null)
			{
				var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
						.FirstOrDefaultAsync(x => x.ID == conferenceId);

				var conferenceUrl = !string.IsNullOrEmpty(conferenceMaster.HomePageUrl) ? conferenceMaster.HomePageUrl :
						ConstValues.SystemWeb + "/MeetingMain/Index/" + conferenceMaster.ConferenceNickName;

				foreach (var conferenceAttendenceInfo in result)
				{
					MailSender sender = new MailSender(conferenceMailServerMaster.MailServer);
					MailAddress from = new MailAddress(conferenceMailServerMaster.Mail);
					MailAddress to = new MailAddress(conferenceAttendenceInfo.Mail);

					MailMessage message = Utility.GetMailContent(new MailModel
					{
						MailRemark = ConstValues.MailSubject.会后调研,
						Language = conferenceMaster.IsInternational ? ConstValues.Language.En : ConstValues.Language.Cn,
						UserName = conferenceAttendenceInfo.FullName,
						ConferenceId = conferenceMaster.ID,
						ConferenceName = conferenceMaster.ConferenceName,
						ConferenceNickName = conferenceMaster.ConferenceNickName,
						ConferenceUrl = !string.IsNullOrEmpty(conferenceMaster.HomePageUrl) ? conferenceMaster.HomePageUrl :
							ConstValues.SystemWeb + "/MeetingMain/Index/" + conferenceMaster.ConferenceNickName,
						QuizUrl = ConstValues.SystemWeb + "/MeetingFeedback/Index/" +
							conferenceId + "/" + quizId + "/" + conferenceAttendenceInfo.ID
					});
					message.To.Add(to);

					if (!string.IsNullOrWhiteSpace(conferenceMailServerMaster.CcMail))
					{
						foreach (string cc in conferenceMailServerMaster.CcMail.Split(ConstValues.chrSemicolon))
						{
							if (!string.IsNullOrWhiteSpace(cc) && cc.Contains(ConstValues.chrAt))
							{
								message.Bcc.Add(new MailAddress(cc.Trim()));
							}
						}
					}

					var strTmp = sender.SendMail(from, message, conferenceMailServerMaster.Password);
					if (!string.IsNullOrEmpty(strTmp))
					{
						strMsg += "\r\n" + "【" + conferenceAttendenceInfo.Mail + "】" + strTmp;
					}
					else
					{
						var sysUserMaster = await DbContext.SysUserMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.Mail == conferenceAttendenceInfo.Mail);
						if (sysUserMaster != null)
						{
							var profileQuizInfo = new ProfileQuizInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfileQuizInfo),
								UserName = sysUserMaster.UserName,
								QuizId = quizId,
								Status = ConstValues.ReplyStatus.未回复,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};
							DbContext.ProfileQuizInfo.Add(profileQuizInfo);
						}
					}

					var info = await DbContext.ConferenceAttendenceInfo.FirstOrDefaultAsync(x => x.ID == conferenceAttendenceInfo.ID);
					if (info != null && string.IsNullOrEmpty(strTmp))
					{
						info.HasSendMail = true;
					}

					await DbContext.SaveChangesAsync();
				}
			}

			if (!string.IsNullOrEmpty(strMsg))
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.FailSendMail + strMsg),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessSendMail),
						JsonRequestBehavior.AllowGet);
			}
		}

		[Route("DownloadImportTemplate/{conferenceId}")]
		public async Task<ActionResult> DownloadImportTemplate(string conferenceId)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", conferenceId);

			var conferenceMaster = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId);

			if (conferenceMaster.IsInternational)
			{
				return File(Resources.import_attendenceInfoEN,
						"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
						$"import_attendenceInfoEN.xlsx");
			}
			else
			{
				return File(Resources.import_attendenceInfoCN,
						"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
						$"import_attendenceInfoCN.xlsx");
			}
		}

		[HttpPost]
		[ValidateAntiForgeryToken]
		[Route("Import/{ConferenceId}")]
		public async Task<JsonResult> Import(ImportAttendenceInfoModel model)
		{
			string controller = RouteData.Values["controller"].ToString();
			string actionName = RouteData.Values["action"].ToString();
			Utility.InsertLog(LoginUser, Request.Url.ToString(), controller, actionName, "Index", model.ConferenceId);

			if (model.ImportFile != null && model.ImportFile.InputStream.Length > 0)
			{
				try
				{
					var result = await this.ImportData(model.ConferenceId, model.ImportFile.InputStream);

					if (!string.IsNullOrEmpty(_importMessage))
					{
						return JsonCamelCase(Utility.CreateFailJsonResult(_importMessage),
								JsonRequestBehavior.AllowGet, true);
					}
					else
					{
						return JsonCamelCase(Utility.CreateSuccessJsonResult(Resources.SuccessImport),
								JsonRequestBehavior.AllowGet, true);
					}
				}
				catch (Exception)
				{
					return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgFileError),
							JsonRequestBehavior.AllowGet, true);
				}
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgInvalidFile),
					JsonRequestBehavior.AllowGet, true);
			}
		}

		private async Task<int> ImportData(string conferenceId, Stream stream)
		{
			var conferenceInfo = await DbContext.ConferenceMaster.AsNoTracking()
					.FirstOrDefaultAsync(x => x.ID == conferenceId);

			XSSFWorkbook workbook;
			workbook = new XSSFWorkbook(stream);

			ISheet sheet = workbook.GetSheetAt(0);
			int rowIndex = 0;
			int recordCount = 0;

			while (true)
			{
				var tmpMsg = string.Empty;
				try
				{
					rowIndex++;
					IRow row = sheet.GetRow(rowIndex);
					if (row == null)
					{
						break;
					}

					#region AttendenceInfo
					var model = new ImportAttendenceInfoModel()
					{
						ConferenceId = conferenceId
					};
					int columnIndex = 0;

					// 参会类型
					if (row.GetCell(columnIndex) != null)
					{
						model.AttendenceIdentity = Utility.ReadExcelField(row.GetCell(columnIndex));

						var attendenceIdentityMaster = await DbContext.AttendenceIdentityMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
									x.ConferenceId == conferenceId &&
									x.IdentityName == model.AttendenceIdentity);

						if (attendenceIdentityMaster != null)
						{
							model.AttendenceIdentityId = attendenceIdentityMaster.ID;
						}
					}

					// 姓名
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.FullName = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.FullName))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.FullName) + "<br/>";
						}
						else if (model.FullName.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.FullName, 100) + "<br/>";
						}
						model.FullName = model.FullName.Replace(ConstValues.strHtmlEnter, string.Empty).Replace(ConstValues.strHtmlChengeLine, string.Empty);
					}

					// 性别
					columnIndex++;
					if (row.GetCell(columnIndex)?.StringCellValue == Resources.Female)
					{
						model.Gender = false;
					}
					else
					{
						model.Gender = true;
					}

					// 职称
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Title = Utility.ReadExcelField(row.GetCell(columnIndex));

						var titleMaster = await DbContext.TitleMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.Status == ConstValues.Status.正常 &&
									x.ConferenceId == conferenceId &&
									x.TitleName == model.Title);

						if (titleMaster != null)
						{
							model.TitleId = titleMaster.ID;
						}
					}

					// 最高学历
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Degree = Utility.ReadExcelField(row.GetCell(columnIndex));

						var degreeMaster = await DbContext.DegreeMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.DegreeName == model.Degree || x.DegreeNameEn == model.Degree);

						if (degreeMaster != null)
						{
							model.DegreeId = degreeMaster.ID;
						}
					}

					// 职务
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Job = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Job.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Job, 100) + "<br/>";
						}
					}

					// 单位
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Affiliation = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Affiliation))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.Affiliation) + "<br/>";
						}
						else if (model.Affiliation.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Affiliation, 100) + "<br/>";
						}
					}

					// 部门
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Department = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Department.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Department, 100) + "<br/>";
						}
					}

					// 国家
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Country = Utility.ReadExcelField(row.GetCell(columnIndex));

						var locationMaster = await DbContext.LocationMaster.AsNoTracking()
								.FirstOrDefaultAsync(x => x.Name == model.Country);

						if (locationMaster != null)
						{
							model.CountryId = locationMaster.ID;
						}
					}

					// 地址
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Address = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Address.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Address, 100) + "<br/>";
						}
					}

					// 邮编
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Zipcode = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Zipcode.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.ZipCode, 100) + "<br/>";
						}
					}

					// 电话
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Telephone = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Telephone.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Telephone, 100) + "<br/>";
						}
					}

					// 手机
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Mobile = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Mobile.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Mobile, 100) + "<br/>";
						}
					}

					// 邮箱
					columnIndex++;
					model.Mail = Utility.ReadExcelField(row.GetCell(columnIndex));
					if (string.IsNullOrEmpty(model.Mail))
					{
						tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.Mail) + "<br/>";
						continue;
					}
					else if (model.Mail.Length > 100)
					{
						tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Mail, 100) + "<br/>";
						continue;
					}

					var mailExist = await DbContext.ConferenceAttendenceInfo.AsNoTracking()
							.AnyAsync(x => x.ConferenceId == conferenceId && x.Mail == model.Mail);
					if (mailExist)
					{
						tmpMsg += model.Mail + Resources.MsgSameMail + "<br/>";
						continue;
					}

					// 身份证
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.CardId = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.CardId.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.CardId, 100) + "<br/>";
						}
					}

					// 币种
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Currency = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.Currency) ||
							(model.Currency != ConstValues.Currency.人民币 && model.Currency != ConstValues.Currency.美元))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.Currency) + "<br/>";
						}
					}

					// 参会费
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.AttendenceFee = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 支付方式
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.PaidType = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (string.IsNullOrEmpty(model.PaidType))
						{
							tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.PaymentType) + "<br/>";
						}
						else
						{
							var conferencePaymentMaster = await DbContext.ConferencePaymentMaster.AsNoTracking()
								.Where(x => x.Status == ConstValues.Status.正常 && x.ConferenceId == conferenceId)
								.Join(DbContext.SysPaymentMaster.AsNoTracking()
									.Where(x => x.Status == ConstValues.Status.正常 &&
										(conferenceInfo.IsInternational ? x.PaymentNameEn == model.PaidType : x.PaymentName == model.PaidType)),
									pay => pay.PayId,
									master => master.ID,
									(pay, master) => new
									{
										Id = pay.ID,
										Name = master.PaymentName,
									})
								.FirstOrDefaultAsync();

							if (conferencePaymentMaster != null)
							{
								model.PaidTypeId = conferencePaymentMaster.Id;
							}
							else
							{
								tmpMsg += string.Format(Resources.MsgImportNotExist, model.Mail, Resources.PaymentType) + "<br/>";
							}
						}
					}

					// 发票抬头
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.InvoiceTitle = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.InvoiceTitle.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.InvoiceTitle, 100) + "<br/>";
						}
					}

					// 税号
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.TaxNum = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.TaxNum.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.TaxNum, 100) + "<br/>";
						}
					}

					// 自定义1
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize1 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义2
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize2 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义3
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize3 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义4
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize4 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义5
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize5 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义6
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize6 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义7
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize7 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义8
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize8 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义9
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize9 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 自定义10
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Customize10 = Utility.ReadExcelField(row.GetCell(columnIndex));
					}

					// 备注
					columnIndex++;
					if (row.GetCell(columnIndex) != null)
					{
						model.Remark = Utility.ReadExcelField(row.GetCell(columnIndex));

						if (model.Remark.Length > 100)
						{
							tmpMsg += string.Format(Resources.MsgImportMaxLength, model.Mail, Resources.Remark, 100) + "<br/>";
						}
					}

					if (!string.IsNullOrEmpty(tmpMsg))
					{
						_importMessage += tmpMsg;
						continue;
					}

					var attendenceId = Utility.GetTableId(ConstValues.TableName.ConferenceAttendenceInfo);
					var conferenceAttendenceInfo = new ConferenceAttendenceInfo
					{
						ID = attendenceId,
						ConferenceId = model.ConferenceId,
						Mail = model.Mail?.Trim(),
						FamilyName = string.Empty,
						FirstName = string.Empty,
						FullName = model.FullName?.Trim(),
						Gender = model.Gender,
						Title = model.TitleId?.Trim(),
						Affiliation = model.Affiliation?.Trim(),
						Telephone = model.Telephone?.Trim(),
						Mobile = model.Mobile?.Trim(),
						AttendenceIdentityId = model.AttendenceIdentityId,
						Country = model.CountryId,
						EssayId = string.Empty,
						FavouriteTopicId = string.Empty,
						HasVisa = false,
						HasHotel = false,
						HasMeal = false,
						HasPage = false,
						HasContributed = false,
						HasPaid = false,
						HasArrived = false,
						HasPrinted = false,
						HasDinner = false,
						HasInvoiced = false,
						HasSendMail = false,
						HasSendPaid = false,
						IsRefund = false,
						TransferEvidenceId = model.ConferenceId.ToString() + ConstValues.strHyphen + LoginUser.UserID,
						TotalFee = 0,
						Discount = 0,
						Currency = model.Currency,
						Sort = ConstValues.DefaultSort,
						Creator = LoginUser.UserName,
						CreateIP = LoginUser.IP,
						CreateDate = DateTime.Now,
						Job = model.Job?.Trim(),
						Department = model.Department?.Trim(),
						Address = model.Address?.Trim(),
						ZipCode = model.Zipcode?.Trim(),
						CardId = model.CardId?.Trim(),
						InvoiceTitle = model.InvoiceTitle?.Trim(),
						TaxNum = model.TaxNum?.Trim(),
						Customize1 = model.Customize1?.Trim(),
						Customize2 = model.Customize2?.Trim(),
						Customize3 = model.Customize3?.Trim(),
						Customize4 = model.Customize4?.Trim(),
						Customize5 = model.Customize5?.Trim(),
						Customize6 = model.Customize6?.Trim(),
						Customize7 = model.Customize7?.Trim(),
						Customize8 = model.Customize8?.Trim(),
						Customize9 = model.Customize9?.Trim(),
						Customize10 = model.Customize10?.Trim(),
						Remark = model.Remark?.Trim(),
						Degree = model.DegreeId,
						PaymentTypeId = model.PaidTypeId,
						QRCode = Utility.CreateQRCode(attendenceId,
								Server.MapPath(Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName)),
								Path.Combine(ConstValues.QRCodeImg, conferenceInfo.ConferenceNickName))
					};
					DbContext.ConferenceAttendenceInfo.Add(conferenceAttendenceInfo);
					#endregion

					#region ProfilePaymentInfo
					if (!string.IsNullOrEmpty(model.AttendenceFee))
					{
						var feeMaster = DbContext.FeeAttendenceMaster.AsNoTracking()
								.FirstOrDefault(x => x.Status == ConstValues.Status.正常 &&
									x.ConferenceId == conferenceId &&
									x.RegisterType == model.AttendenceFee &&
									x.Currency == model.Currency);
						if (feeMaster != null && feeMaster.Price.HasValue)
						{
							double originFee = feeMaster.Price.Value;
							double discountFee = feeMaster.Discount.HasValue ? feeMaster.Discount.Value : feeMaster.Price.Value;

							var profilePaymentInfo = new ProfilePaymentInfo
							{
								ID = Utility.GetTableId(ConstValues.TableName.ProfilePaymentInfo),
								UserName = LoginUser.UserName,
								AttendenceId = attendenceId,
								FeeType = ConstValues.FeeType.参会费,
								FeeId = feeMaster.ID,
								Count = 1,
								Fee = originFee,
								Discount = discountFee,
								Currency = feeMaster.Currency,
								Creator = LoginUser.UserName,
								CreateIP = LoginUser.IP,
								CreateDate = DateTime.Now
							};

							DbContext.ProfilePaymentInfo.Add(profilePaymentInfo);

							conferenceAttendenceInfo.TotalFee = originFee;
							conferenceAttendenceInfo.Discount = discountFee;
						}
					}
					#endregion

					await DbContext.SaveChangesAsync();

					recordCount++;
				}
				catch (Exception)
				{
					continue;
				}
			}

			return await Task.FromResult(recordCount);
		}

		public async Task<JsonCamelCaseResult> GetCurrentPageItem(string conferenceId)
		{
			var result = await DbContext.ConferenceAttendenceForm.AsNoTracking()
					.Where(x => x.Status == ConstValues.Status.正常 &&
						x.ConferenceId == conferenceId)
					.OrderBy(x => x.DisplayPage)
					.ThenBy(x => x.Sort)
					.ThenBy(x => x.DisplayName)
					.ToListAsync();

			return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result),
					JsonRequestBehavior.AllowGet);
		}

		public async Task<JsonCamelCaseResult> GetCurrentPageValue(string id)
		{
			var sql = from info in DbContext.ConferenceAttendenceInfo.AsNoTracking().Where(x => x.ID == id)
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.版面费)
					on info.ID equals profilePaymentInfo.AttendenceId into t1
				  from pageFee in t1.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.参会费)
					on info.ID equals profilePaymentInfo.AttendenceId into t2
				  from attendenceFee in t2.DefaultIfEmpty()
				  join profilePaymentInfo in DbContext.ProfilePaymentInfo.AsNoTracking().Where(x => x.FeeType == ConstValues.FeeType.餐费)
					on info.ID equals profilePaymentInfo.AttendenceId into t3
				  from mealFee in t3.DefaultIfEmpty()
				  join conferenceMaster in DbContext.ConferenceMaster.AsNoTracking()
				       on info.ConferenceId equals conferenceMaster.ID
				  select new
				  {
					  ID = info.ID,
					  ConferenceId = info.ConferenceId,
					  FamilyName = info.FamilyName,
					  FirstName = info.FirstName,
					  FullName = info.FullName,
					  Gender = info.Gender,
					  Title = info.Title,
					  Degree = info.Degree,
					  Job = info.Job,
					  Affiliation = info.Affiliation,
					  Department = info.Department,
					  CardId = info.CardId,
					  AttendenceIdentityId = info.AttendenceIdentityId,
					  EssayId = info.EssayId,
					  Mail = info.Mail,
					  Telephone = info.Telephone,
					  Mobile = info.Mobile,
					  Country = info.Country,
					  State = info.StateStr,
					  City = info.CityStr,
					  Address = info.Address,
					  ZipCode = info.ZipCode,
					  InvoiceTitle = info.InvoiceTitle,
					  TaxNum = info.TaxNum,
					  AddressAndTel = info.AddressAndTel,
					  Bank = info.Bank,
					  BankAccount = info.BankAccount,
					  InvoiceId = info.InvoiceId,
					  PaymentTypeId = info.PaymentTypeId,
					  FavouriteTopicId = info.FavouriteTopicId,
					  Currency = info.Currency,
					  PageFeeId = pageFee.FeeId,
					  AttendenceFeeId = attendenceFee.FeeId,
					  MealFeeId = mealFee.FeeId,
					  Sort = info.Sort,
					  Remark = info.Remark,
					  HasPaid = info.HasPaid,
					  IsInternational = conferenceMaster.IsInternational,
				  };

			var sqlResult = await sql.ToListAsync();

			var result = sqlResult.Select(x => new
			{
				ID = x.ID,
				ConferenceId = x.ConferenceId,
				FamilyName = x.FamilyName,
				FirstName = x.FirstName,
				FullName = x.FullName,
				Gender = x.Gender == true ? Resources.Male : Resources.Female,
				Title = x.Title,
				Degree = x.Degree,
				Job = x.Job,
				Affiliation = x.Affiliation,
				Department = x.Department,
				CardId = x.CardId,
				AttendenceIdentityId = x.AttendenceIdentityId,
				Mail = x.Mail,
				Telephone = x.Telephone,
				Mobile = x.Mobile,
				Country = x.Country,
				State = x.State,
				City = x.City,
				Address = x.Address,
				ZipCode = x.ZipCode,
				InvoiceTitle = x.InvoiceTitle,
				TaxNum = x.TaxNum,
				AddressAndTel = x.AddressAndTel,
				Bank = x.Bank,
				BankAccount = x.BankAccount,
				InvoiceId = x.InvoiceId,
				PaymentTypeId = x.PaymentTypeId,
				FavouriteTopic = x.FavouriteTopicId.Split(ConstValues.chrSemicolon),
				Currency = x.Currency,
				PageFeeId = x.PageFeeId,
				AttendenceFeeId = x.AttendenceFeeId,
				MealFeeId = x.MealFeeId,
				Sort = x.Sort,
				Remark = x.Remark,
				HasPaid = x.HasPaid,
			});

			if (result.Count() > 0)
			{
				return JsonCamelCase(Utility.CreateSuccessJsonResult(string.Empty, result.FirstOrDefault()),
						JsonRequestBehavior.AllowGet);
			}
			else
			{
				return JsonCamelCase(Utility.CreateFailJsonResult(Resources.MsgRecordNotExist),
						JsonRequestBehavior.AllowGet);
			}
		}
	}
}